package com.ydkj.a37e_mall.Classes.Acitivity.BaseActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.BaseExpandableListAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshScrollView;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.ydkj.a37e_mall.Classes.Applicatiom.MyApplication;
import com.ydkj.a37e_mall.Classes.Model.Request.DebitcardReq;
import com.ydkj.a37e_mall.Classes.Model.Request.GetTreasureReq;
import com.ydkj.a37e_mall.Classes.Model.Request.Postrecharge;
import com.ydkj.a37e_mall.Classes.Model.Request.PostwithdrawReq;
import com.ydkj.a37e_mall.Classes.Model.Request.TreasureRecordReq;
import com.ydkj.a37e_mall.Classes.Model.Response.DebitcardResp;
import com.ydkj.a37e_mall.Classes.Model.Response.GetTreasureResp;
import com.ydkj.a37e_mall.Classes.Model.Response.TreasureRecordResp;
import com.ydkj.a37e_mall.R;
import com.ydkj.a37e_mall.Resource.Utils.Async_http_get;
import com.ydkj.a37e_mall.Resource.Utils.Async_http_post;
import com.ydkj.a37e_mall.Resource.Utils.CommonUtil;
import com.ydkj.a37e_mall.Resource.Utils.Const;
import com.ydkj.a37e_mall.Resource.Utils.GsonImpl;
import com.ydkj.a37e_mall.Resource.Utils.SharedPreferencesUtil;
import com.ydkj.a37e_mall.Resource.View.CustomProgressDialog;
import com.ydkj.a37e_mall.Resource.View.MyExpandableListView;
import com.ydkj.a37e_mall.Resource.View.StatusBarUtil;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import cz.msebera.android.httpclient.Header;


/**
 * Created by Administrator on 2017/1/11.
 * 我的余额
 */

public class MyBalanceAcitivity extends BaseActivity implements View.OnClickListener {
    private Activity mActivity;
    private SharedPreferencesUtil sharedPreferencesUtil;
    private MyApplication myApplication;
    private ImageView back_img;
    private TextView tv_balance_money;
    private LinearLayout lly_balance_recharge, lly_balance_transferaccounts, lly_balance_transfertb;
    private RelativeLayout rly_balance_withdrawals;
    private PullToRefreshScrollView my_balance_ptrscrollview;
    private MyExpandableListView my_balance_expandablelv;
    private MyBananceExpandableLvAdapter myBananceExpandableLvAdapter;


    private List<TreasureRecordResp.ResultEntity.DataEntity> gtouplist;
    private List<List<TreasureRecordResp.ResultEntity.DataEntity>> childlist;

    private PopupWindow transfermon_Pop;
    private EditText et_pop_transfer_money_name, et_pop_transfer_money_card, et_pop_transfer_money_num; //转帐Pop的et
    private TextView tv_tramsfer_balance, tv_tramsfer_servicecharge, tv_tramsfer_confirm;   //转帐Pop的tv
    private ImageView img_pop_transfer_down;   //转帐Pop的img

    private PopupWindow transfermon_tb_Pop;
    private EditText et_pop_transfer_tb_num;//转通宝Pop的et
    private TextView tv_tramsfer_tb_balance, tv_tramsfer_tb_servicecharge, tv_tramsfer_tb_confirm, tv_tramsfer_mytb, tv_pop_transfer_tb_icon;   //转通宝Pop的tv
    private ImageView img_pop_transfer_tb_down;   //转tbPop的img
    private LinearLayout lly_pop_type1, lly_pop_type2;

    private PopupWindow transfermon_withdrawals_Pop;
    private EditText et_pop_withdrawals_name, et_pop_withdrawals_card, et_pop_withdrawals_num; //提现Pop的et
    private TextView tv_withdrawals_balance, tv_withdrawals_servicecharge, tv_withdrawals_confirm, tv_withdrawals_changecard;   //提现Pop的tv
    private ImageView img_pop_withdrawals_down;   //转帐Pop的img

    private int code;//判断是充值（2）还是转通宝（1）
    private String balance;//余额

    private static final int LOAD = 0;// 加载
    private static final int REFRESH = 1;//刷新
    private static final int MORE = 2;// 更多
    public int page;
    private String account;
    private String name;
    private String identifier_no;
    private String mobile;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.my_balance);
        mActivity = this;
        init();
        initWindow();
    }

    private void initWindow() {
        StatusBarUtil.setColor(mActivity, getResources().getColor(R.color.Af7261b), 0);

    }

    private void init() {

        sharedPreferencesUtil = SharedPreferencesUtil.getInstance(mActivity);
        myApplication = MyApplication.getInstance();
        back_img = (ImageView) mActivity.findViewById(R.id.img_back);
        back_img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        tv_balance_money = (TextView) mActivity.findViewById(R.id.tv_balance_money);

        lly_balance_recharge = (LinearLayout) mActivity.findViewById(R.id.lly_balance_recharge);
        lly_balance_transferaccounts = (LinearLayout) mActivity.findViewById(R.id.lly_balance_transferaccounts);
        lly_balance_transfertb = (LinearLayout) mActivity.findViewById(R.id.lly_balance_transfertb);

        rly_balance_withdrawals = (RelativeLayout) mActivity.findViewById(R.id.rly_balance_withdrawals);
        Getdebitcard(REFRESH);//获取银行卡信息

        GetTreasure();//获取账户余额
        TreasureRecord(REFRESH);//获取账户流水号
        gtouplist = new ArrayList<>();
        childlist = new ArrayList<>();
        myBananceExpandableLvAdapter = new MyBananceExpandableLvAdapter(gtouplist, childlist);

        my_balance_expandablelv = (MyExpandableListView) mActivity.findViewById(R.id.my_balance_expandablelv);
        my_balance_expandablelv.setGroupIndicator(null);
        my_balance_expandablelv.setDivider(null);
        my_balance_expandablelv.setAdapter(myBananceExpandableLvAdapter);

        my_balance_ptrscrollview = (PullToRefreshScrollView) mActivity.findViewById(R.id.my_balance_ptrscrollview);
        my_balance_ptrscrollview.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
        my_balance_ptrscrollview.setOnRefreshListener2(new PullToRefreshBase.OnRefreshListener2<ScrollView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ScrollView> refreshView) {
                GetTreasure();
                TreasureRecord(REFRESH);
                Log.e("ssss", "down");
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ScrollView> refreshView) {
                TreasureRecord(MORE);
                Log.e("ssss", "up");
            }
        });

        lly_balance_recharge.setOnClickListener(this);
        lly_balance_transferaccounts.setOnClickListener(this);
        lly_balance_transfertb.setOnClickListener(this);
        rly_balance_withdrawals.setOnClickListener(this);
    }


    //获取我的余额
    private void GetTreasure() {
        CustomProgressDialog.createDialog(mActivity).show();
        GetTreasureReq req = new GetTreasureReq();
        req.setUuid(myApplication.getDataEntity().getUuid());
        req.setType("4");

        RequestParams params = new RequestParams();
        params.put("token", sharedPreferencesUtil.getAccessToken());
        params.put("secret", req.getSecret());
        Async_http_get.get(Const.COMMON_ADDRESS + req.urlString(), params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                CustomProgressDialog.Dismiss();
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                Log.e("url", "response==" + response);
                if (errno.equals("000")) {
                    GetTreasureResp resp = GsonImpl.get().toObject(response.toString(), GetTreasureResp.class);
                    balance = resp.getResult().getData().getBalance();
                    tv_balance_money.setText(balance);

                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
            }
        });
    }

    //获取我的余额流水记录
    private void TreasureRecord(final int type) {
        TreasureRecordReq req = new TreasureRecordReq();
        req.setUuid(myApplication.getDataEntity().getUuid());
        req.setType("4");
        if (type == LOAD || type == REFRESH) {
            page = 1;
        } else {
            page = gtouplist.size() / 10 + 1;
        }
        req.setPage(page + "");
        req.setPage_size("10");
        RequestParams params = new RequestParams();
        params.put("token", sharedPreferencesUtil.getAccessToken());
        params.put("secret", req.getSecret());
        Async_http_get.get(Const.COMMON_ADDRESS + req.urlString(), params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
//                CustomProgressDialog.Dismiss();
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                Log.e("ssss", "通宝流水response==" + response);
                if (errno.equals("000")) {
                    TreasureRecordResp resp = GsonImpl.get().toObject(response.toString(), TreasureRecordResp.class);
                    if (type == LOAD || type == REFRESH) {
                        gtouplist.clear();
                        gtouplist.addAll(resp.getResult().getData());
                        for (int i = 0; i < gtouplist.size(); i++) {
                            List<TreasureRecordResp.ResultEntity.DataEntity> list = new ArrayList<TreasureRecordResp.ResultEntity.DataEntity>();
                            list.add(gtouplist.get(i));
                            childlist.add(list);
                        }
                    } else {

                        gtouplist.addAll(resp.getResult().getData());
                        for (int i = 0; i < gtouplist.size(); i++) {
                            List<TreasureRecordResp.ResultEntity.DataEntity> list = new ArrayList<TreasureRecordResp.ResultEntity.DataEntity>();
                            list.add(gtouplist.get(i));
                            childlist.add(list);
                        }
                    }
                    if (gtouplist.size() % 10 > 0) {
                        my_balance_ptrscrollview.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
                    } else {
                        my_balance_ptrscrollview.setMode(PullToRefreshBase.Mode.BOTH);
                    }


                    myBananceExpandableLvAdapter.notifyDataSetChanged();
                    my_balance_ptrscrollview.onRefreshComplete();

                } else {
                    myBananceExpandableLvAdapter.notifyDataSetChanged();
                    my_balance_ptrscrollview.onRefreshComplete();
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                CustomProgressDialog.Dismiss();
                CommonUtil.showToast(mActivity, "网络连接失败");
                myBananceExpandableLvAdapter.notifyDataSetChanged();
                my_balance_ptrscrollview.onRefreshComplete();
            }
        });
    }

    //获取我的银行卡
    private void Getdebitcard(final int type) {
        DebitcardReq req = new DebitcardReq();
        req.setUuid(myApplication.getDataEntity().getUuid());
        if (type == LOAD || type == REFRESH) {
            page = 1;
        } else {
//            page = hotProductInfoList.size() / 10 + 1;
        }
        req.setPage(page + "");
        req.setPage_size("10");
        RequestParams params = new RequestParams();
        params.put("token", sharedPreferencesUtil.getAccessToken());
        params.put("secret", req.getSecret());
        Async_http_get.get(Const.COMMON_ADDRESS + req.urlString(), params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                Log.e("url", "hotProductList_json==" + response);
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                if (errmsg.equals("暂无银行卡")) {
                    CommonUtil.showToast(mActivity, errmsg);
                    return;
                }
                if (errno.equals("000")) {
                    Log.e("url", "银行卡列表response==>" + response);
                    DebitcardResp resp = GsonImpl.get().toObject(response.toString(), DebitcardResp.class);
                    account = resp.getResult().getData().get(0).getAccount();
                    name = resp.getResult().getData().get(0).getName();
                    identifier_no = resp.getResult().getData().get(0).getIdentifier_no();
                    mobile = resp.getResult().getData().get(0).getMobile();

                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                CommonUtil.showToast(mActivity, "网络连接失败");
            }
        });
    }


    //提现接口
    private void Postwithdraw(String account, String name, String amount) {
        CustomProgressDialog.createDialog(mActivity).show();
        PostwithdrawReq req = new PostwithdrawReq();
        req.setUuid(myApplication.getDataEntity().getUuid());
        req.setAccount(account);
        req.setName(name);
        req.setAmount(amount);
        RequestParams params = new RequestParams();
        params.put("token", sharedPreferencesUtil.getAccessToken());
        params.put("secret", req.getSecret());

        Async_http_post.post(Const.COMMON_ADDRESS + req.urlString(), params, new JsonHttpResponseHandler() {
                    @Override
                    public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                        super.onSuccess(statusCode, headers, response);
                        CustomProgressDialog.Dismiss();
                        String errno = response.optString("errno");
                        String errmsg = response.optString("errmsg");
                        Log.e("url", "提现response==" + response);
                        if (errno.equals("000")) {
                            CommonUtil.showToast(mActivity, errmsg);
                            transfermon_withdrawals_Pop.dismiss();
                        }
                    }

                    @Override
                    public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                        super.onFailure(statusCode, headers, responseString, throwable);
                        CustomProgressDialog.Dismiss();
                        transfermon_withdrawals_Pop.dismiss();
                        CommonUtil.showToast(mActivity, "网络连接失败");
                    }
                }

        );

    }

    //充值接口
    private void Postrecharge(String amount) {
        CustomProgressDialog.createDialog(mActivity).show();
        Postrecharge req = new Postrecharge();
        req.setUuid(myApplication.getDataEntity().getUuid());
        req.setAccount(account);
        req.setName(name);
        req.setAmount(amount);
        req.setIdentifier_no(identifier_no);
        req.setMobile(mobile);
        RequestParams params = new RequestParams();
        params.put("token", sharedPreferencesUtil.getAccessToken());
        params.put("secret", req.getSecret());
        Async_http_post.post(Const.COMMON_ADDRESS + req.urlString(), params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                super.onSuccess(statusCode, headers, response);
                CustomProgressDialog.Dismiss();
                String errno = response.optString("errno");
                String errmsg = response.optString("errmsg");
                Log.e("url", "充值response==" + response);
                if (errno.equals("000")) {
                    CommonUtil.showToast(mActivity, errmsg);
                    transfermon_tb_Pop.dismiss();
                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
            }
        });
    }

    @Override
    public void onClick(View view) {
        WindowManager.LayoutParams lp;

        switch (view.getId()) {

            case R.id.lly_balance_transferaccounts://转账

                CommonUtil.showToast(mActivity, "暂未开放");
//                showPopulwindow1();
//
//                lp = getWindow().getAttributes();
//                lp.alpha = 0.5f;
//                getWindow().setAttributes(lp);
//                transfermon_Pop.showAtLocation(view, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
//                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);//弹出软键盘
//                imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

                break;
            case R.id.lly_balance_transfertb://提现

                showPopulwindow3();
                lp = getWindow().getAttributes();
                lp.alpha = 0.5f;
                getWindow().setAttributes(lp);
                transfermon_withdrawals_Pop.showAtLocation(view, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                InputMethodManager imm1 = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);//弹出软键盘
                imm1.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

                break;

            case R.id.rly_balance_withdrawals://提现
                showPopulwindow3();
                lp = getWindow().getAttributes();
                lp.alpha = 0.5f;
                getWindow().setAttributes(lp);
                transfermon_withdrawals_Pop.showAtLocation(view, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                InputMethodManager imm2 = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);//弹出软键盘
                imm2.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

                break;
            case R.id.lly_balance_recharge://充值
                code = 2;
                showPopulwindow2();
                lp = getWindow().getAttributes();
                lp.alpha = 0.5f;
                getWindow().setAttributes(lp);

                transfermon_tb_Pop.showAtLocation(view, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
                InputMethodManager imm3 = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);//弹出软键盘
                imm3.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);

                break;
        }

    }

    //转账

    private void showPopulwindow1() {


        View contentView = LayoutInflater.from(mActivity).inflate(R.layout.pop_transfer_accounts, null);

        img_pop_transfer_down = (ImageView) contentView.findViewById(R.id.img_pop_transfer_down);

        et_pop_transfer_money_name = (EditText) contentView.findViewById(R.id.et_pop_transfer_money_name);
        et_pop_transfer_money_card = (EditText) contentView.findViewById(R.id.et_pop_transfer_money_card);
        et_pop_transfer_money_num = (EditText) contentView.findViewById(R.id.et_pop_transfer_money_num);

        tv_tramsfer_balance = (TextView) contentView.findViewById(R.id.tv_tramsfer_balance);
        tv_tramsfer_servicecharge = (TextView) contentView.findViewById(R.id.tv_tramsfer_servicecharge);
        tv_tramsfer_confirm = (TextView) contentView.findViewById(R.id.tv_tramsfer_confirm);


        transfermon_Pop = new PopupWindow(contentView, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT, true);
        transfermon_Pop.setTouchable(true);

        transfermon_Pop.setAnimationStyle(R.style.mypopwindow_anim_style);

        ColorDrawable dw = new ColorDrawable(0x00000000);
        //设置PopupWindow弹出窗体的背景
        transfermon_Pop.setBackgroundDrawable(dw);
        transfermon_Pop.setOutsideTouchable(true);
        transfermon_Pop.setFocusable(true);

        //设置Pop不会被软键盘覆盖
        transfermon_Pop.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
        transfermon_Pop.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

        transfermon_Pop.setTouchInterceptor(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {

                Log.i("mengdd", "onTouch : ");

                return false;
                // 这里如果返回true的话，touch事件将被拦截
                // 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
            }
        });
//        mPopupWindow.setBackgroundDrawable(getResources().getDrawable(R.color.colorAccent));

        transfermon_Pop.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {

                WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();
                lp.alpha = 1;
                mActivity.getWindow().setAttributes(lp);
            }
        });


        //关闭Pop
        img_pop_transfer_down.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                transfermon_Pop.dismiss();
            }
        });

        //确认转账
        tv_tramsfer_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
    }

    //转通宝
    private void showPopulwindow2() {

        View contentView = LayoutInflater.from(mActivity).inflate(R.layout.pop_transfer_tb, null);

        img_pop_transfer_tb_down = (ImageView) contentView.findViewById(R.id.img_pop_transfer_tb_down);
        et_pop_transfer_tb_num = (EditText) contentView.findViewById(R.id.et_pop_transfer_tb_num);
        tv_tramsfer_tb_balance = (TextView) contentView.findViewById(R.id.tv_tramsfer_tb_balance);
        tv_tramsfer_tb_servicecharge = (TextView) contentView.findViewById(R.id.tv_tramsfer_tb_servicecharge);
        tv_tramsfer_tb_confirm = (TextView) contentView.findViewById(R.id.tv_tramsfer_tb_confirm);
        tv_tramsfer_mytb = (TextView) contentView.findViewById(R.id.tv_tramsfer_mytb);
        tv_pop_transfer_tb_icon = (TextView) contentView.findViewById(R.id.tv_pop_transfer_tb_icon);
        lly_pop_type1 = (LinearLayout) contentView.findViewById(R.id.lly_pop_type1);
        lly_pop_type2 = (LinearLayout) contentView.findViewById(R.id.lly_pop_type2);

        transfermon_tb_Pop = new PopupWindow(contentView, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT, true);
        transfermon_tb_Pop.setTouchable(true);

        transfermon_tb_Pop.setAnimationStyle(R.style.mypopwindow_anim_style);

        ColorDrawable dw = new ColorDrawable(0x00000000);
        //设置PopupWindow弹出窗体的背景
        transfermon_tb_Pop.setBackgroundDrawable(dw);
        transfermon_tb_Pop.setOutsideTouchable(true);
        transfermon_tb_Pop.setFocusable(true);

        //设置Pop不会被软键盘覆盖
        transfermon_tb_Pop.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
        transfermon_tb_Pop.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        transfermon_tb_Pop.setTouchInterceptor(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {

                Log.i("mengdd", "onTouch : ");

                return false;
                // 这里如果返回true的话，touch事件将被拦截
                // 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
            }
        });
//        mPopupWindow.setBackgroundDrawable(getResources().getDrawable(R.color.colorAccent));

        transfermon_tb_Pop.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {

                WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();
                lp.alpha = 1;
                mActivity.getWindow().setAttributes(lp);
            }
        });

        if (code == 1) {
            tv_pop_transfer_tb_icon.setText("余额转通宝");
            tv_tramsfer_tb_balance.setText("余额: 123132");
            lly_pop_type1.setVisibility(View.GONE);
            tv_tramsfer_tb_confirm.setText("确认转账");
        } else if (code == 2) {
            tv_pop_transfer_tb_icon.setText("充值");
            tv_tramsfer_tb_balance.setText("余额:" + balance);
            lly_pop_type2.setVisibility(View.GONE);
            tv_tramsfer_tb_confirm.setText("确认充值");

        }


        //关闭Pop
        img_pop_transfer_tb_down.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                transfermon_tb_Pop.dismiss();
            }
        });

        //确认转账
        tv_tramsfer_tb_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (code == 1) {
                } else if (code == 2) {
                    if (et_pop_transfer_tb_num.getText().toString().equals("")) {
                        Toast.makeText(mActivity, "充值的金额不能为空", Toast.LENGTH_SHORT).show();

                    } else {
                        Postrecharge(et_pop_transfer_tb_num.getText().toString());

                    }
                }
            }
        });
    }

    //提现
    private void showPopulwindow3() {

        View contentView = LayoutInflater.from(mActivity).inflate(R.layout.pop_transfer_withdrawals, null);

        img_pop_withdrawals_down = (ImageView) contentView.findViewById(R.id.img_pop_withdrawals_down);

        et_pop_withdrawals_name = (EditText) contentView.findViewById(R.id.et_pop_withdrawals_name);
        et_pop_withdrawals_card = (EditText) contentView.findViewById(R.id.et_pop_withdrawals_card);
        et_pop_withdrawals_num = (EditText) contentView.findViewById(R.id.et_pop_withdrawals_num);

        tv_withdrawals_balance = (TextView) contentView.findViewById(R.id.tv_withdrawals_balance);
        tv_withdrawals_servicecharge = (TextView) contentView.findViewById(R.id.tv_withdrawals_servicecharge);
        tv_withdrawals_confirm = (TextView) contentView.findViewById(R.id.tv_withdrawals_confirm);
        tv_withdrawals_changecard = (TextView) contentView.findViewById(R.id.tv_withdrawals_changecard);
        tv_withdrawals_balance.setText("余额:" + balance);

        transfermon_withdrawals_Pop = new PopupWindow(contentView, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT, true);
        transfermon_withdrawals_Pop.setTouchable(true);

        transfermon_withdrawals_Pop.setAnimationStyle(R.style.mypopwindow_anim_style);

        ColorDrawable dw = new ColorDrawable(0x00000000);
        //设置PopupWindow弹出窗体的背景
        transfermon_withdrawals_Pop.setBackgroundDrawable(dw);
        transfermon_withdrawals_Pop.setOutsideTouchable(true);
        transfermon_withdrawals_Pop.setFocusable(true);

        //设置Pop不会被软键盘覆盖
        transfermon_withdrawals_Pop.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
        transfermon_withdrawals_Pop.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

        transfermon_withdrawals_Pop.setTouchInterceptor(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {

                Log.i("mengdd", "onTouch : ");

                return false;
                // 这里如果返回true的话，touch事件将被拦截
                // 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
            }
        });
//        mPopupWindow.setBackgroundDrawable(getResources().getDrawable(R.color.colorAccent));

        transfermon_withdrawals_Pop.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {

                WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();
                lp.alpha = 1;
                mActivity.getWindow().setAttributes(lp);
            }
        });

        //关闭Pop
        img_pop_withdrawals_down.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                transfermon_withdrawals_Pop.dismiss();
            }
        });


        //确认转账
        tv_withdrawals_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (et_pop_withdrawals_name.getText().toString().equals("")) {
                    return;
                }
                if (et_pop_withdrawals_card.getText().toString().equals("")) {
                    return;
                }
                if (et_pop_withdrawals_num.getText().toString().equals("")) {
                    return;
                }

                Postwithdraw(et_pop_withdrawals_name.getText().toString(), et_pop_withdrawals_card.getText().toString(), et_pop_withdrawals_num.getText().toString());
            }
        });

        //更换银行卡
        tv_withdrawals_changecard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(mActivity, MyBankcardActivity.class));
            }
        });
    }


    private class MyBananceExpandableLvAdapter extends BaseExpandableListAdapter {
        private List<TreasureRecordResp.ResultEntity.DataEntity> group;
        private List<List<TreasureRecordResp.ResultEntity.DataEntity>> child;


        public MyBananceExpandableLvAdapter(List<TreasureRecordResp.ResultEntity.DataEntity> group, List<List<TreasureRecordResp.ResultEntity.DataEntity>> child) {

            this.group = group;
            this.child = child;
        }

        @Override
        public int getGroupCount() {
            return group.size();
        }

        @Override
        public int getChildrenCount(int groupPosition) {
            return child.get(groupPosition).size();
        }

        @Override
        public TreasureRecordResp.ResultEntity.DataEntity getGroup(int groupPosition) {
            return group.get(groupPosition);
        }

        @Override
        public TreasureRecordResp.ResultEntity.DataEntity getChild(int groupPosition, int childPosition) {
            return child.get(childPosition).get(childPosition);
        }

        @Override
        public long getGroupId(int groupPosition) {
            return groupPosition;
        }

        @Override
        public long getChildId(int groupPosition, int childPosition) {
            return childPosition;
        }


        /**
         * 显示：group
         */
        @Override
        public View getGroupView(int groupPosition, boolean isExpanded,
                                 View convertView, ViewGroup parent) {
            ViewHolder holder;
            if (convertView == null) {
                convertView = LayoutInflater.from(mActivity).inflate(
                        R.layout.balance_group_list, null);
                holder = new ViewHolder();

                holder.img_group = (ImageView) convertView.findViewById(R.id.img_group);
                holder.img_balance_group_type = (ImageView) convertView.findViewById(R.id.img_balance_group_type);
                holder.tv_balance_group_num = (TextView) convertView.findViewById(R.id.tv_balance_group_num);
                holder.tv_balance_group_message = (TextView) convertView.findViewById(R.id.tv_balance_group_message);
                holder.tv_balance_group_time = (TextView) convertView.findViewById(R.id.tv_balance_group_time);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }

            if (getGroup(groupPosition).getTurnover().equals("1")) {
                holder.img_balance_group_type.setBackground(getResources().getDrawable(R.mipmap.bank_add));
            } else {
                holder.img_balance_group_type.setBackground(getResources().getDrawable(R.mipmap.bank_rectangle_small));
            }

            holder.tv_balance_group_message.setText(getGroup(groupPosition).getType());
            holder.tv_balance_group_num.setText(getGroup(groupPosition).getPrice());
            holder.tv_balance_group_time.setText(getGroup(groupPosition).getCreated_at());
            //箭头的切换
            if (isExpanded) {
                holder.img_group.setImageResource(R.mipmap.array_up);
            } else {
                holder.img_group.setImageResource(R.mipmap.array_down);
            }
            return convertView;

        }

        /**
         * 显示：child
         */
        @Override
        public View getChildView(int groupPosition, int childPosition,
                                 boolean isLastChild, View convertView, ViewGroup parent) {
            ViewHolder holder;
            if (convertView == null) {
                convertView = LayoutInflater.from(mActivity).inflate(R.layout.balance_child_list, null);
                holder = new ViewHolder();
                holder.tv_balance_child_order = (TextView) convertView.findViewById(R.id.tv_balance_child_order);
                holder.tv_balance_child_store = (TextView) convertView.findViewById(R.id.tv_balance_child_store);
                holder.tv_balance_child_adress = (TextView) convertView.findViewById(R.id.tv_balance_child_adress);
                holder.tv_balance_child_phone = (TextView) convertView.findViewById(R.id.tv_balance_child_phone);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            holder.tv_balance_child_order.setText(getChild(groupPosition, childPosition).getSn());
            holder.tv_balance_child_store.setText(getChild(groupPosition, childPosition).getName());
            holder.tv_balance_child_adress.setText(getChild(groupPosition, childPosition).getAddress());
            holder.tv_balance_child_phone.setText(getChild(groupPosition, childPosition).getMobile());
            return convertView;
        }

        class ViewHolder {
            private TextView tv_balance_group_num, tv_balance_group_message, tv_balance_group_time;
            private ImageView img_balance_group_type, img_group;
            private TextView tv_balance_child_order, tv_balance_child_store, tv_balance_child_adress, tv_balance_child_phone;

        }

        @Override
        public boolean isChildSelectable(int groupPosition, int childPosition) {
            return false;
        }

        @Override
        public boolean hasStableIds() {
            return false;
        }
    }


}
